package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.dto.DeleteDTO;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.NewsService;
import com.example.mybatisplus.model.domain.News;


/**
 * 前端控制器
 *
 * @author lxp
 * @version v1.0
 * @since 2023-01-06
 */
@Controller
@RequestMapping("/api/news")
public class NewsController {

    private final Logger logger = LoggerFactory.getLogger(NewsController.class);

    @Autowired
    private NewsService newsService;

    @PostMapping("save")
    @ResponseBody
    public JsonResponse save(@RequestBody News news) {
        newsService.news(news);
        return JsonResponse.success(true);
    }

    @GetMapping("list")
    @ResponseBody
    public JsonResponse list(News news, PageDTO pageDTO) {
        Page<News> page = newsService.pageList(news, pageDTO);
        return JsonResponse.success(page);
    }

    @PostMapping("removeByIds")
    @ResponseBody
    public JsonResponse removeByIds(@RequestBody DeleteDTO deleteDTO) {
        boolean b = newsService.removeByIds(deleteDTO.getIds());
        return JsonResponse.success(b);
    }
}

